/////////////////////////////////////////////////////////////////////////////////////////////////////
//Viper Racing II
//Ian "Woody" Nicholas
//Website: http://www.geocities.com/bigcrazyalien
//Email: ghotistix@hotmail.com
//Made with Div Games Studio 2
//http://www.div-arena.com
/////////////////////////////////////////////////////////////////////////////////////////////////////

PROGRAM viper_racing_2;
GLOBAL
 viperid;

 status=0;

 fpg=1;
 coursefpg;
 menufpg;

 tinyfont;
 smallfont;
 medfont;
 bigfont;
 titlefont;

 skidsound;
 dirtsound;
 enginesound;
 switchsound2;
 switchsound1;
 lapsound;
 winsound;
 rainsound;

 coursenumber=1;

 counter;

 checkpoint_passed;
 lap=1;

 maxspeed=170;

 timeh;
 times;
 timem;

BEGIN

 set_fps(44,5);
 set_mode(800600);

 tinyfont=load_fnt("vr2tiny.fnt");
 smallfont=load_fnt("vr2small.fnt");
 medfont=load_fnt("vr2med.fnt");
 bigfont=load_fnt("vr2big.fnt");
 titlefont=load_fnt("vr2title.fnt");

 menufpg=load_fpg("c:/div2/fpg/menu.fpg");

 LOOP

  IF (status==0)
   mainmenu();
  END

  IF (status==2)
   mainmenu();
   //credits();
  END

  IF (status==4)
   mainmenu();
   //options();
  END

  IF (status==6)
   racemenu();
  END

  IF (status==8)
   mainmenu();
   //upgradesmenu();
  END

  IF (status==10)
   race();
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS mainmenu();
BEGIN
 status=1;
 file=menufpg;

 put_screen(0,109);

 write(titlefont,400,70,4,"Viper Racing II");
 write(smallfont,400,130,4,"Demo Version");

 write_int(medfont,50,50,4,&fpg);

 write(medfont,400,220,4,"New Game");
 button(400,220,6);
 write(medfont,400,290,4,"Load Game");
 button(400,290,6);
 write(medfont,400,360,4,"Credits");
 button(400,360,2);
 write(medfont,400,430,4,"Options");
 button(400,430,4);
 write(medfont,400,500,4,"Exit");
 button(400,500,50);

 fade_on();

 LOOP

  mouse.file=menufpg;
  mouse.graph=1;

  IF (key(_esc) OR status>20)
   fade_off();
   exit("Coward",0);
  END

  IF (status<0 OR status>1)
   mouse.size=0;
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS racemenu();
BEGIN
 status=7;
 file=menufpg;

 put_screen(0,110);

 write_int(medfont,50,50,4,&fpg);

 write(titlefont,400,70,4,"Race Menu");
 write(medfont,400,220,4,"Course");
 write_int(medfont,400,270,4,&coursenumber);
 write(smallfont,400,310,4,"Press Left or Right to change");
 write(medfont,400,500,4,"Press Enter to begin");

 fade_on();

 LOOP

  counter=counter+1;

  IF (key(_left) AND counter>6 AND coursenumber>1)
   counter=0;
   coursenumber=coursenumber-1;
  END

  IF (key(_right) AND counter>6 AND coursenumber<6)
   counter=0;
   coursenumber=coursenumber+1;
  END

  IF (key(_enter))
   fade_off();
   delete_text(all_text);
   status=10;
  END

  IF (key(_esc))
   fade_off();
   delete_text(all_text);
   status=0;
  END

  IF (status>7 OR status<6)
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS button(x,y,goto_status);
PRIVATE
 goto_status;

BEGIN
 file=menufpg;
 graph=112;
 z=550;
 x=400;
 flags=4;

 LOOP

  IF (collision(TYPE mouse))
   size=size+1;
   flags=0;
  ELSE
   size=size-1;
   flags=4;
  END

  IF (collision(TYPE mouse) AND mouse.left)
   size=size-1;
   fade_off();
   delete_text(all_text);
   status=goto_status;
  END

  IF (size>100)
   size=100;
  END

  IF (size<90)
   size=90;
  END

  IF (status<0 OR status>1)
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS race();
BEGIN
 status=11;

 IF (fpg<11)
  //unload_fpg(menufpg);
  IF (coursenumber==1)
   coursefpg=load_fpg("course1.fpg");
   fpg=11;
  END
  IF (coursenumber==2)
   coursefpg=load_fpg("course2.fpg");
   fpg=12;
  END
  IF (coursenumber==3)
   coursefpg=load_fpg("course3.fpg");
   fpg=13;
  END
  IF (coursenumber==4)
   coursefpg=load_fpg("course4.fpg");
   fpg=14;
  END
  IF (coursenumber==5)
   coursefpg=load_fpg("course5.fpg");
   fpg=15;
  END
  IF (coursenumber==6)
   coursefpg=load_fpg("course6.fpg");
   fpg=16;
  END
 END

 file=coursefpg;

 viperid=viper();
 course();
 pavement();
 tvscreen();
 checkpoint();
 finishline();

 start_scroll(0,coursefpg,3,3,0,0);
 scroll.camera=viperid;

 fade_on();

 timer=0;
 timem=0;
 times=0;
 timeh=0;

 write_int(medfont,50,50,4,&fpg);

 write_int(smallfont,20,20,4,&timem);
 write_int(smallfont,60,20,4,&times);
 write_int(smallfont,100,20,4,&timeh);

LOOP

  IF (NOT FADING)
   screen_copy(0,coursefpg,4,175,75,550,300);
  END

  timeh=timer;

  IF (timer>99)
   timer=0;
   times=times+1;
  END

  IF (times>59)
   times=0;
   timem=timem+1;
  END

  IF (key(_esc))
   fade_off();
   delete_text(all_text);
   stop_scroll(0);
   unload_fpg(coursefpg);
   fpg=1;
   status=6;
  END

  IF (status>11 OR status<10)
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS viper();
PRIVATE
 turning;
 speed;
 speed_x;
 speed_y;
 prevx;
 prevy;
 disp_speed;

BEGIN
 file=coursefpg;
 resolution=10;
 graph=2;
 x=12000;
 y=18000;
 z=-10;

 ctype=c_scroll;

     write(smallfont,760,590,7,"MPH");
 write_int(medfont,700,590,7,&disp_speed);

 LOOP

  prevx=x;
  prevy=y;

  x=x+(speed_x/18);
  y=y+(speed_y/18);

  advance(speed/3);

  disp_speed=fget_dist(x,y,prevx,prevy);

  speed_x=(speed_x*60)/61;
  speed_y=(speed_y*60)/61;
  turning=(turning*5)/6;

  IF (disp_speed>64)
   angle=angle+turning;
  ELSE
   angle=angle+((turning*disp_speed)/64);
  END

  IF (key(_up) AND disp_speed<maxspeed)
   speed=speed+1;
   speed_x+=get_distx(angle,40);
   speed_y+=get_disty(angle,40);
  ELSE
   speed=speed-1;
  END

  IF (key(_left))
   turning=turning+900;
  END

  IF (key(_right))
   turning=turning-900;
  END

  IF (turning>5900)
   turning=5900;
  END

  IF (speed<0)
   speed=0;
  END

  IF (x<1700)
   x=1700;
   IF (speed>2)
    speed=speed-7;
    speed_x=(speed_x*5)/6;
   END
  END

  IF (x>25750)
   x=25750;
   IF (speed>2)
    speed=speed-7;
    speed_x=(speed_x*5)/6;
   END
  END

  IF (y<1750)
   y=1750;
   IF (speed>2)
    speed=speed-7;
    speed_y=(speed_y*5)/6;
   END
  END

  IF (y>19700)
   y=19700;
   IF (speed>2)
    speed=speed-7;
    speed_y=(speed_y*5)/6;
   END
  END

  FRAME;

  IF (collision(TYPE course))
   IF (speed>2)
    speed=speed-7;
    speed_x=(speed_x*5)/6;
    speed_y=(speed_y*5)/6;
   END

   IF (key(_up))
    dirt(1);
    dirt(2);
    dirt(3);
    dirt(4);
   END
  END

  IF (collision(TYPE checkpoint))
   checkpoint_passed=1;
  END

  IF (collision(TYPE finishline) AND checkpoint_passed==1)
   checkpoint_passed=0;
   lap=lap+1;
  END

  IF (status>11 OR status<10)
   BREAK;
  END

 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS dirt(wheel);
PRIVATE
 wheel;

BEGIN
 file=coursefpg;
 graph=102;
 x=father.x/10;
 y=father.y/10;
 z=11;
 //angle=father.angle;

 IF (wheel==1 OR wheel==2)
  xadvance(father.angle,-23);
 ELSE
  xadvance(father.angle,23);
 END

 IF (wheel==1 OR wheel==3)
  xadvance(father.angle+90000,11);
 ELSE
  xadvance(father.angle-90000,11);
 END

 ctype=c_scroll;

 FRAME;

 IF (map_get_pixel(coursefpg,1,x-175,y-175)<>0 AND map_get_pixel(coursefpg,1,x-175,y-175)<>4)
  map_xput(coursefpg,1,101,x-175,y-175,father.angle,100,0);
  RETURN;
 ELSE
  RETURN;
 END

END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS tvscreen();
BEGIN
 file=coursefpg;
 x=431;
 y=1454;
 graph=4;
 z=-1;

 ctype=c_scroll;

 LOOP

 IF (coursenumber==1)
  x=431;
  y=1454;
  angle=0;
 END

 IF (coursenumber==2)
  x=801;
  y=822;
  angle=0;
 END

 IF (coursenumber==3)
  x=1136;
  y=770;
  angle=-18000;
 END

 IF (coursenumber==4)
  x=913;
  y=489;
  angle=0;
 END

 IF (coursenumber==5)
  x=771;
  y=670;
  angle=0;
 END

 IF (coursenumber==6)
  x=670;
  y=1563;
  angle=0;
 END

  IF (status>11 OR status<10)
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS finishline();
BEGIN
 file=coursefpg;
 x=1250;
 y=1845;
 graph=6;
 size=70;

 ctype=c_scroll;

 LOOP

  IF (status>11 OR status<10)
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS checkpoint();
BEGIN
 file=coursefpg;
 graph=7;
 z=100;

 ctype=c_scroll;

 LOOP

  IF (coursenumber==1)
   x=798;
   y=1062;
  END

  IF (coursenumber==2)
   x=642;
   y=636;
  END

  IF (coursenumber==3)
   x=1554;
   y=1427;
  END

  IF (coursenumber==4)
   x=1639;
   y=321;
  END

  IF (coursenumber==5)
   x=2140;
   y=733;
  END

  IF (coursenumber==6)
   x=1214;
   y=345;
  END

  IF (coursenumber==7)
   x=0;
   y=0;
  END

  IF (status>11 OR status<10)
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS course();
BEGIN
 file=coursefpg;
 resolution=10;
 graph=1;
 x=13750;
 y=10750;
 z=9;

 ctype=c_scroll;

 LOOP

  IF (status>11 OR status<10)
   BREAK;
  END

  FRAME;
 END
END





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





PROCESS pavement();
BEGIN
 file=coursefpg;
 resolution=10;
 graph=10;
 x=13750;
 y=10750;
 z=10;

 ctype=c_scroll;

 LOOP

  IF (status>11 OR status<10)
   BREAK;
  END

  FRAME;
 END
END



